$(function () {
    $("#jqGrid").jqGrid({
        url:baseURL+"sys/terminalInfo/list" ,
        datatype: "json",
        colModel: [
            { label: 'SN', name: 'sn', width: 80,align:'center' , sortable: false},
            { label: '终端号', name: 'merchantCode', width: 80, align:'center' , sortable: false},
            { label: '机具型号', name: 'model', width: 45,align:'center' , sortable: false},
            { label: '机具名称', name: 'terminalName', width: 45,align:'center'},
            { label: '激活状态', name: 'isActivation', width:45, formatter:function(value, options, row){
                return value=='1'?"未激活":(value=='2'?"已激活":"禁用")},align:'center' , sortable: false},
            { label: '激活时间', name: 'activationDate', width:75,align:'center' , sortable: false,formatter:function (value,options,row) {
                    return value==null?"-":value;
                }},
            { label: '返现金额', name: 'reapAmount', width: 60,align:'center',formatter:function (value,options,row) {
                    return value==null?"0.00":value;
                } , sortable: false},
            { label: '是否报备', name: 'isReport', width: 50,align:'center',formatter:function (value,options,row) {
                    return value==2?"是":"否";
                } , sortable: false},
			{ label: '是否线上', name: 'isOnline', width: 50,align:'center',formatter:function (value,option,row) {
                    return value==1?"是":"否";
                } , sortable: false},
            { label: '返现人姓名', name: 'name', width: 75,align:'center',formatter:function (value,options,row) {
                    return value==null?"-":value;
                } , sortable: false},
            { label: '返现人手机', name: 'phone', width: 75,align:'center',formatter:function (value,options,row) {
                    return value==null?"-":value;
                } , sortable: false},
            { label: '当前归属', name: 'ownerName', width: 75,align:'center',formatter:function (value,options,row) {
                    return value==null?"-":value;
                } , sortable: false},


        ],
		viewrecords: true,
        height: 375,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

    bindType();

});


var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            startSn:null,
            endSn:null,
            merchantCode:null,
            activation:0,
            terminalType:0,
            ownName:null,
            reapName:null,
            report:0
        },
        activations:[
            {
                value:0,
                name:"请选择激活状态"
            },
            {
                value:1,
                name:"未激活"
            },
            {
                value:2,
                name:"已激活"
            },
            {
                value:3,
                name:"禁用"
            }
        ],
        reports:[
            {
                value:0,
                name:"请选择报备状态"
            },
            {
                value:1,
                name:"未报备"
            },
            {
                value:2,
                name:"已报备"
            }
        ],
        terminalTypes:[],
        showList: true,
        conShow:false,
        title:null,
        terminal:{
            terminalId:null,
            sn:null,
            merchantCode:null,
            reapAmount:null,
            model:null,
            terminalType:null,
            isReport:null,
            isOnline:null,
            isActivation:null,
            activationDate:null
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean: function () {
            vm.showList = true;
            vm.q = {
                startSn:null,
                endSn:null,
                merchantCode:null,
                activation:0,
                terminalType:0,
                ownName:null,
                reapName:null,
                report:0
            };
            $("#jqGrid").jqGrid('setGridParam', {page: 1});
            vm.reload();
        },
        reload: function () {
            vm.showList = true;

            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'merchantCode': vm.q.merchantCode,
                    'terminalType': vm.q.terminalType,
                    'startSn': vm.q.startSn,
                    'endSn':vm.q.endSn,
                    "activation": vm.q.activation,
                    'ownName':vm.q.ownName,
                    'reapName':vm.q.reapName,
                    'report':vm.q.report
                },
                page: 1
            }).trigger("reloadGrid");
            bindType();
        },

        download: function () {
            //下载当前所查询的文件
            window.location.href=baseURL + "sys/terminalInfo/download";
        }


    }
});

function bindType() {

        $.getJSON(baseURL + "sys/terminalType/list", function (r) {
            vm.$set(vm.terminalTypes, 0, {
                terminalType: 0,
                terminalName: "请选择类型"
            });
            for (var i = 0; i < r.page.length; i++) {
                vm.$set(vm.terminalTypes, (i + 1), r.page[i]);
            }

        })


}